package com.example.smsalarm;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;

public class TextMessageReceiver extends BroadcastReceiver{

	
	public void onReceive(Context context, Intent intent)
	{
		Bundle bundle=intent.getExtras();
		 if (bundle == null)
		       return;
		Object[] pdus=(Object[])bundle.get("pdus");
		for (int i = 0; i < pdus.length; i++) {
	          SmsMessage SMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);
	          String sender = SMessage.getOriginatingAddress();
	          String body = SMessage.getMessageBody();

	         // A custom Intent that will used as another Broadcast
	         Intent in = new Intent("SmsMessage.intent.MAIN").
	         putExtra("get_msg", sender+":"+body);
	         context.sendBroadcast(in);

				
			}
			
	}
}
